package com.studyyoun.android.androidcommonbaselibrary.activity;

/**
 * Created by androidlongs on 17/7/14.
 * 站在顶峰，看世界
 * 落在谷底，思人生
 */

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.View;

/**
 *
 * CommonBaseActivity Base基类封装
 */

public abstract class CommonBaseActivity  extends AppCompatActivity{

    protected Context mContext;
    protected Handler mHandler = new Handler(Looper.getMainLooper());
    public DisplayMetrics mDisplayMetrics;
    public float mScaledDensity;

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=this.getApplicationContext();
        setContentView(getCommonLayoutId());
        View view= View.inflate(this,getCommonLayoutId(),null);
        Intent intent = getIntent();
        getAllIntentExtraDatas(intent);
        commonInitView(view);
        commonFunction();

        mDisplayMetrics = mContext.getResources().getDisplayMetrics();
        mScaledDensity = mDisplayMetrics.scaledDensity;

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run () {
                commonDelayFunction ();
            }
        },200);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {

        }
    }

    //获取所有的传递数据
    protected abstract void getAllIntentExtraDatas (Intent intent);
    //获取布局ID
    protected abstract int getCommonLayoutId ();
    //初始化控件
    protected abstract void commonInitView (View view);
    //常用功能 处理
    protected abstract void commonFunction ();
    //延时常用功能 处理
    protected abstract void commonDelayFunction ();


}
